let express = require("express");
let http = require("http");
let https = require("https");
let fs = require("fs");
var request = require('request');
var bodyParser = require('body-parser');
// Configuare https
const httpsOption = {
  key : fs.readFileSync("./https/2_bus.zuduia.com.key"),
  cert: fs.readFileSync("./https/1_bus.zuduia.com_bundle.crt")
}
// Create service
let app = express();
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post('/bus/search/getByName', function (req, res) { // 根据名字获取公交信息
  request({
    method:"POST",
    url: "http://xxtapi.gzyyjt.net/wxxt-api/system/search/getByName",
    headers:{
        "content-type":"application/json"
    },
    body: req.body,
    json: true      //这个针对body是不是支持json
  },(error,response,body)=>{
    res.send(body);
  })
})
app.post('/bus/search/getStatics', function (req, res) { // 根据公交信息获取公交站列表
  request({
    method:"POST",
    url: "http://xxtapi.gzyyjt.net/wxxt-api/bus/route/getStatics",
    headers:{
        "content-type":"application/json"
    },
    body: req.body,
    json: true      //这个针对body是不是支持json
  },(error,response,body)=>{
    res.send(body);
  })
})
app.post('/bus/search/getDynamic', function (req, res) { // 获取公交动态信息
  request({
    method:"POST",
    url: "http://xxtapi.gzyyjt.net/wxxt-api//bus/route/getDynamic",
    headers:{
        "content-type":"application/json"
    },
    body: req.body,
    json: true      //这个针对body是不是支持json
  },(error,response,body)=>{
    res.send(body);
  })
})
http.createServer(app).listen(80);
https.createServer(httpsOption, app).listen(443);
